package ignite.repository;

import org.apache.ignite.springdata22.repository.IgniteRepository;
import org.apache.ignite.springdata22.repository.config.Query;
import org.apache.ignite.springdata22.repository.config.RepositoryConfig;
import org.ignite.entity.Person;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.query.Param;

import javax.cache.Cache;
import java.util.List;

@RepositoryConfig(cacheName = "person")
public interface PersonRepository extends IgniteRepository<Person, Integer> {

    List<Cache.Entry<Integer, Person>> findByFirstName(String name);
 
    @Query("SELECT id FROM Person WHERE Id > ?")
    List<Integer> selectId(Integer Id, Pageable pageable);
 
    @Query("select * from person")
    List<Cache.Entry<Integer, Person>> selectAll(Pageable pageable);
 
    @Query("SELECT max(id) from person")
    Integer getMaxId();


    @Query("SELECT * from person where id=:id")
    Person selectPersonById(@Param("id") Integer id);
 
    @Query(value = "select * from person where id > :Id and firstName = :firstName")
    List<Cache.Entry<Integer, Person>> findByManyParams(@Param("Id") Integer Id, @Param("firstName") String firstName);
 
    @Query("update person set firstName = :firstName where Id = :Id")
    void updateById(@Param("Id") Integer Id, @Param("firstName") String firstName);
 
    void deleteById(Integer Id);
 
}